/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.gov.ana.service;

import br.gov.ana.dao.MedHidrometeorologicaDAO;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.jws.WebService;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.ejb.Stateless;

/**
 *
 * @author lucas.nunes
 */
@WebService(serviceName = "ResconjWS")
@Stateless()
public class ResconjWS {

    /**
     * This is a sample web service operation
     */
    @WebMethod(operationName = "consultarDadosResolucao")
    public RetornoWS consultarDadosResolucao(@WebParam(name = "codigoFlu") String codigoFlu, @WebParam(name = "ano") int ano, @WebParam(name = "variavel") int variavel) {

        MedHidrometeorologicaDAO dao = new MedHidrometeorologicaDAO();

        RetornoWS retorno = new RetornoWS();
        CabecalhoWS cabecalho = new CabecalhoWS();

        try {
            cabecalho.setCodigoFlu(codigoFlu);
            cabecalho.setAno(ano);
            cabecalho.setVariavel(getVariavel(variavel));
            List<CabecalhoWS> header = new ArrayList<CabecalhoWS>();
            header.add(cabecalho);

            retorno.setCabecalho(header);
            retorno.setMedicao(dao.getListaEstacoesPorEstacao(codigoFlu, ano, variavel));
        } catch (Exception ex) {
            Logger.getLogger(ResconjWS.class.getName()).log(Level.SEVERE, null, ex);
        }
        return retorno;
    }
    
    private String getVariavel(int variavel) {
        String retorno;
        switch (variavel) {
            case 1:
                retorno = "Chuva";
                break;
            case 2:
                retorno = "Nivel";
                break;
            case 3:
                retorno = "Vazao";
                break;
            default:
                retorno = "Chuva";
                break;
        }
        return retorno;
    }
}
